<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='ttbl' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        html {
            background: #fff;
        }
    </style>
</head>

<body>
<div class="layui-container">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

        <form:form commandName="goods" class="layui-form" id="form">

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend><fmt:message key='xgkcxx' /></legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label"><fmt:message key='spsku' /></label>
                <div class="layui-input-block">
                    <table class="layui-table" lay-size="sm" id="feijin-sku-table">
                        <thead>
                        <tr>
                            <th><fmt:message key='gg' /></th>
                            <th><fmt:message key='sjbh' /></th>
                            <th><fmt:message key='kcs' /></th>
                            <th><fmt:message key='xsj' /></th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${goods.skus}" var="sku">
                            <tr>
                                <td>${sku.skuNames}</td>
                                <td>${sku.code}</td>
                                <td><input type="text" class="layui-input feijin-store" data-id="${sku.id}" value="${sku.store}"/></td>
                                <td><input type="text" class="layui-input feijin-price" data-id="${sku.id}" value="${sku.price}"/></td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="layui-input-block">
                <div style="display: none"><input type="button" value="<fmt:message key='bc' />" class="layui-btn" id="submit" lay-filter="submit" lay-submit></div>
            </div>

        </form:form>
    </div>
</div>

<script>

    $(function () {

        layui.use(['form', 'laydate'], function () {

            var form = layui.form;
            var laydate = layui.laydate;

            form.on('submit(submit)', function () {

                var data = [];

                $(".feijin-store").each(function (index, item) {
                    var store = $(item).val();
                    var id = $(this).attr("data-id");
                    var price = $(".feijin-price:eq(" + index + ")").val();

                    data.push(id + "-" + store + ":" + price);
                });

                $.ajax({
                    url: "${web_domain}/merchant/goods/modifyStore",
                    type: "post",
                    dataType: "json",
                    data: {
                        "_method": "put",
                        "data": data.join(";")
                    },
                    success: function (result) {
                        if (result.status) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.$("#search").click();
                        } else {
                            layer.alert(result.message);
                        }
                    }

                });


            });


        });

    });
</script>
</body>
</fmt:bundle>
</html>